package net.plankton.CamRestart;

import java.io.IOException;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class Restart extends Thread {

	@Override
	public void run() {
		HttpClient client = new HttpClient();
//		client.getParams().setAuthenticationPreemptive(true);
		Credentials defaultcreds = new UsernamePasswordCredentials("administrator", "");
		client.getState().setCredentials(AuthScope.ANY, defaultcreds);
		PostMethod post = new PostMethod("http://192.168.1.90/adm/file.cgi");
		post.setDoAuthentication(true);
		post.addParameter("this_file","password.htm");
		post.addParameter("next_file","password.htm");
		post.addParameter("todo","restart");
		post.addParameter("message","");
		try {
			client.executeMethod(post);
			String body  = post.getResponseBodyAsString();
			System.err.println(body);
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		new Restart().run();
	}
	
}
